翻訳と辞書
Words near each other
・ Cycle of violence
・ Cycle oil
・ Cycle Oregon
・ Cycle per second
・ Cycle polo
・ Cycle polo at the 1908 Summer Olympics
・ Cycle Préparatoire Intégré de Bordeaux
・ Cycle Psycho
・ Cycle Queens of America
・ Cycle racing in Belgium
・ Cycle rank
・ Cycle Repeats
・ Cycle responder
・ Cycle rickshaw
・ Cycle Sluts from Hell
Cycle sort
・ Cycle space
・ Cycle speedway
・ Cycle sport
・ Cycle stealing
・ Cycle time variation
・ Cycle to Work scheme
・ Cycle Toronto
・ Cycle track
・ Cycle World
・ Cycle-Scoot
・ Cycleanine
・ CycleBeads
・ Cyclecar
・ Cyclecide


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Cycle sort : ウィキペディア英語版
Cycle sort

Cycle sort is an in-place, unstable sorting algorithm, a comparison sort that is theoretically optimal in terms of the total number of writes to the original array, unlike any other in-place sorting algorithm. It is based on the idea that the permutation to be sorted can be factored into cycles, which can individually be rotated to give a sorted result.
Unlike nearly every other sort, items are ''never'' written elsewhere in the array simply to push them out of the way of the action. Each value is either written zero times, if it's already in its correct position, or written one time to its correct position. This matches the minimal number of overwrites required for a completed in-place sort.
Minimizing the number of writes is useful when making writes to some huge data set is very expensive, such as with EEPROMs like Flash memory where each write reduces the lifespan of the memory.
== Algorithm ==
The following algorithm finds cycles and rotates them, giving a sorted result. Arrays are zero-indexed.
# Sort an array in place and return the number of writes.
procedure cycleSort(array):
writes = 0

# Loop through the array to find cycles to rotate.
for cycleStart from 0 to length(array) - 2, inclusive:
item = array()

# Find where to put the item.
pos = cycleStart
for i from cycleStart + 1 to length(array) - 1, inclusive:
if array() < item:
pos += 1

# If the item is already there, this is not a cycle.
if pos == cycleStart:
continue

# Otherwise, put the item there or right after any duplicates.
while item == array():
pos += 1
array(), item = item, array()
writes += 1

# Rotate the rest of the cycle.
while pos != cycleStart:
# Find where to put the item.
pos = cycleStart
for i from cycleStart + 1 to length(array) - 1, inclusive
if array() < item:
pos += 1

# Put the item there or right after any duplicates.
while item == array():
pos += 1
array(), item = item, array()
writes += 1

return writes

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Cycle sort」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.